Class {
	#name : 'ReRenameInstanceVariableDriverTest',
	#superclass : 'ReDriverTest',
	#category : 'Refactoring-UI-Tests',
	#package : 'Refactoring-UI-Tests'
}

{ #category : 'tests' }
ReRenameInstanceVariableDriverTest >> testInvalidNameFollowedByAValidNameExpectSuccess [

	| rbclasses driver requestDialog |
	rbclasses := RBClassEnvironment classes: { MyClassARoot }.
	driver := ReRenameInstanceVariableDriver new
		          scopes: { rbclasses }
		          variable: #unusedVar1
		          for: MyClassARoot.
	"There is already a variable named `unusedVar2` in the class `MyClassRoot`"

	self setUpDriver: driver.

	requestDialog := MockObject new.
	requestDialog on: #openModal respond: #unusedVar2.
	requestDialog on: #openModal respond: #okName.
	requestDialog on: #title: respond: 'nothing'.
	requestDialog on: #text: respond: 'nothing'.
	driver requestDialog: requestDialog.
	
	"it like a smoke test and for the moment we cannot control better what happen."
	driver runRefactoring
]

{ #category : 'tests' }
ReRenameInstanceVariableDriverTest >> testValidNameAndUndefinedVariable [

	| rbclasses driver |	
	rbclasses := RBClassEnvironment classes: { MyClassARoot }.
	driver := ReRenameInstanceVariableDriver new
		          scopes: { rbclasses }
		          variable: #inexistantVariable
		          for: MyClassARoot.
		
	"Variable `inexistantVariable` is not defined in `MyClassARoot`"
	self setUpDriver: driver.
 	driver runRefactoring.
	
	"Nothing happened since the vairable does not exist and we stop immediately."
	self assert: driver refactoring model changes changes size equals: 0
]

{ #category : 'tests' }
ReRenameInstanceVariableDriverTest >> testValidNameAndUnusedVariable [

	| rbclasses driver requestDialog |
	rbclasses := RBClassEnvironment classes: { MyClassARoot }.
	driver := ReRenameInstanceVariableDriver new
		          scopes: { rbclasses }
		          variable: #unusedVar1
		          for: MyClassARoot.
	self setUpDriver: driver.
	

	requestDialog := MockObject new.
	requestDialog on: #openModal respond: #unusedVar1a.
	requestDialog on: #title: respond: 'nothing'.
	requestDialog on: #text: respond: 'nothing'.
	driver requestDialog: requestDialog.

	driver runRefactoring.
	self assert: driver refactoring changes changes size equals: 1
]

{ #category : 'tests' }
ReRenameInstanceVariableDriverTest >> testValidNameAndUsedVariable [

	| rbclasses driver requestDialog |
	rbclasses := RBClassEnvironment classes: { MyClassARoot }.
	driver := ReRenameInstanceVariableDriver new
		          scopes: { rbclasses }
		          variable: #instVarName1
		          for: MyClassARoot.
	self setUpDriver: driver.

	requestDialog := MockObject new.
	requestDialog on: #openModal respond: #instVarName1a.
	requestDialog on: #title: respond: 'nothing'.
	requestDialog on: #text: respond: 'nothing'.
	driver requestDialog: requestDialog.
	
	driver runRefactoring.
	"Renaming the references to the variable is not encapsulated in change objects, therefore the only change is the renaming of the variable itself."


	self assert: driver refactoring changes changes size equals: 1
]
